#include <cstdio>

int main( )
{
    int f[ 22 ], i, m, t, n, s;
    f[ 0 ] = 1; f[ 1 ] = 2;
    for ( m = 2; f[ m - 1 ] + f[ m - 2 ] < 25000; m++ )
        f[ m ] = f[ m - 1 ] + f[ m - 2 ];
    scanf("%d", &t);
    while ( t-- )
    {
        s = 0;
        scanf("%d", &n);
        for ( i = m - 1; i > 0; i-- )
            if ( n >= f[ i ] )
            {
                n -= f[ i ];
                s += f[ i - 1 ];
            }
        printf("%d\n", s);
    }
    return 0;
}
